﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TanashCMS.Business;
using TanashCMS.Business.Task;

public partial class manager_websites_Details : CMSManagementPageBase
{
    private TanashWebsite website = null;
    protected int WebsiteID { get { return int.Parse(Request.QueryString["wid"]); } }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            DataBind();
    }

    public override void DataBind()
    {
        website = (TanashWebsite) Configuration.GetCurrentSession().Get(typeof (TanashWebsite), WebsiteID);
        txtTitle.Text = website.Title;
        txtURL.Text = website.URL;
        txtHostHeaders.Text = website.HostHeader;
        txtSystemName.Text = website.SubFolderName;

        base.DataBind();
    }

    protected void btnSaveWebsite_Click(object sender, EventArgs e)
    {
        website = (TanashWebsite)Configuration.GetCurrentSession().Get(typeof(TanashWebsite), WebsiteID);
        website.Title = txtTitle.Text;
        website.URL = txtURL.Text;
        website.HostHeader = txtHostHeaders.Text;
        website.SubFolderName = txtSystemName.Text;
        Configuration.GetCurrentSession().Save(website);
        Configuration.GetCurrentSession().Flush();
        ShowSystemFeedback("The website has been updated.");
    }

    protected void fvOptions_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        DataBind();
    }
    protected void odsOptions_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
    {

    }
    protected void fvOptions_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        e.Values.Add("WebsiteID", Request.QueryString["wid"]);
    }

    protected void btnAdd_OnClick(object sender, EventArgs e)
    {
        WebsiteOption option = new WebsiteOption();
        option.WebsiteID = WebsiteID;
        option.OptionTitle = txtNewOptionTitle.Text;
        option.OptionValue = txtNewOptionValue.Text;
        Configuration.GetCurrentSession().Save(option);
        Configuration.GetCurrentSession().Flush();
        GridView1.DataBind();
        txtNewOptionTitle.Text = "";
        txtNewOptionValue.Text = "";
        Response.Redirect("details.aspx?wid=" + WebsiteID.ToString());
    }
}
